﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RPGProject.GameWorld
{
    /// <summary>
    /// An immutable class that deals with script properties
    /// </summary>
    class PropertyLiteral
    {
        /// <summary>
        /// A list in sequence of the subsections of the properties
        /// </summary>
        private readonly Queue<String> propertyValues;
        /// <summary>
        /// Creates a PropertyLiteral from a Queue, only inside the class can create one this way.
        /// </summary>
        /// <param name="qs"></param>
        private PropertyLiteral(Queue<String> qs)
        {
            this.propertyValues = qs;
        }
        /// <summary>
        /// Parses a propert of form "xxx.yyyy.zz" into "xxx" -> "yyyy" -> "zz"
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static PropertyLiteral ParseProperty(String str)
        {
            String[] strArr = str.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries);
            Queue<String> toPropLiteral = new Queue<string>();
            foreach (String s in strArr)
                toPropLiteral.Enqueue(s);
            return new PropertyLiteral(toPropLiteral);
        }
        /// <summary>
        /// Size of the remaining literal.
        /// </summary>
        public int Size
        {
            get { return this.propertyValues.Count; }
        }
        /// <summary>
        /// The very first property.
        /// </summary>
        public String Front
        {
            get { return this.propertyValues.Peek(); }
        }
        /// <summary>
        /// Gets the rest of the property minus the first element
        /// </summary>
        public PropertyLiteral Next
        {
            get
            {
                Queue<String> qs = new Queue<string>(this.propertyValues);
                qs.Dequeue();
                return new PropertyLiteral(qs);
            }
        }
    }
}
